extends CharacterBody2D

var speed := 100
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var graphic: Node2D = $Graphic

func _physics_process(delta: float) -> void:
	move()
	animation_handler()

func move() -> void:
	var direction := Input.get_axis("move_left", "move_right")
	velocity.x = direction * speed
	graphic.scale.x = -1 if direction < 0 else 1
	move_and_slide()

func animation_handler() -> void:
	if velocity.x == 0:
		animation_player.play("idle")
	else:
		animation_player.play("run")
